<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>退货单据查询</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/metro-blue/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/icon.css">
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/js/date.js"></script>
    <script type="text/javascript">


        function formatUser(val, row) {
            return val.trueName + "&nbsp;(" + val.userName + ")&nbsp;";
        }


        function searchReturn() {
            var supplierId;
            if (isNaN($("#s_supplier").combobox("getValue"))) {
                supplierId = "";
            } else {
                supplierId = $("#s_supplier").combobox("getValue");
            }
            $("#dg").datagrid({
                url: '/admin/returnList/list',
                queryParams: {
                    returnNumber: $("#s_returnNumber").val(),
                    "supplier.id": supplierId,
                    state: $("#s_state").combobox("getValue"),
                    bReturnDate: $("#s_bReturnDate").datebox("getValue"),
                    eReturnDate: $("#s_eReturnDate").datebox("getValue")
                }
            });
        }

        function formatSupplier(val, row) {
            return val.name;
        }

        function formatAmountPayable(val, row) {
            return "¥" + val;
        }

        function formatUser(val, row) {
            return val.trueName;
        }

        function formatPrice(val, row) {
            return "¥" + val;
        }

        function formatTotal(val, row) {
            return "¥" + val;
        }

        function deleteReturn() {
            var selectedRows=$("#dg").datagrid("getSelections");
            if(selectedRows.length!=1){
                $.messager.alert("系统提示","请选择一条要删除的退货单！");
                return;
            }
            var id=selectedRows[0].id;
            $.messager.confirm("系统提示","<span style='color: red'>删除退货单后将无法恢复，是否删除?</span>",function(r){
                if(r){
                    $.post("/admin/returnList/delete",{id:id},function(result){
                        if(result.success){
                            $("#dg").datagrid("reload");
                            $("#dg2").datagrid("reload");
                        }else{
                            $.messager.alert("系统提示",result.errorInfo);
                        }
                    },"json");
                }
            });
        }


        $(document).ready(function () {

            $("#s_bReturnDate").datebox("setValue", genLastMonthDayStr()); // 设置上个月日期
            $("#s_eReturnDate").datebox("setValue", genTodayStrAddOne()); // 设置当前日期

            $("#dg").datagrid({
                onClickRow: function (index, row) {
                    $("#dg2").datagrid({
                        url: '/admin/returnList/listGoods',
                        queryParams: {
                            returnListId: row.id
                        }
                    });
                }
            });
        });
    </script>
</head>
<body class="easyui-layout" style="margin: 1px">
<div region="north" style="height: 350px">
    <table id="dg" title="退货单据查询" class="easyui-datagrid"
           fitColumns="true" rownumbers="true" singleSelect="true"
           fit="true" url="/admin/returnList/list" toolbar="#tb">
        <thead>
        <th field="id" width="20" align="center" hidden="true">退货单ID</th>
        <th field="returnNumber" width="30" align="center">退货单号</th>
        <th field="returnDate" width="20" align="center">退货日期</th>
        <th field="supplier" width="50" align="center" formatter="formatSupplier">供应商</th>
        <th field="amountPayable" width="20" align="right" formatter="formatAmountPayable">退货金额</th>
        <th field="user" width="20" align="center" formatter="formatUser">操作员</th>
        <th field="remarks" width="100" align="center">备注</th>
        </thead>
    </table>

    <div id="tb">
        <fieldset style="border-color: #E7F0FF">
            <legend>查询设置</legend>
            &nbsp;单据号&nbsp;
            <input type="text" id="s_returnNumber" size="15" onkeydown="if(event.keyCode==13) searchReturn()"/>
            &nbsp;&nbsp;&nbsp;供应商：&nbsp;<input class="easyui-combobox" id="s_supplier" name="supplier.id"
                                               style="width: 200px"
                                               data-options="required:true,panelHeight:'auto',valueField:'id',textField:'name',url:'/admin/supplier/comboList'"/>
            &nbsp;&nbsp;&nbsp;是否付款&nbsp;
            <select class="easyui-combobox" id="s_state" style="width: 100px" editable="false" panelHeight="auto">
                <option value="">全部</option>
                <option value="1">已付</option>
                <option value="2">未付</option>
            </select>
            &nbsp;&nbsp;&nbsp;日期：&nbsp;
            <input id="s_bReturnDate" class="easyui-datebox" editable=false style="width:120px"/>
            &nbsp;&nbsp;-&nbsp;&nbsp;
            <input id="s_eReturnDate" class="easyui-datebox" editable=false style="width:120px"/>
            &nbsp;&nbsp;<a href="javascript:searchReturn()" class="easyui-linkbutton" iconCls="icon-search"
                           plain="true">搜索</a>
            &nbsp;&nbsp;<a href="javascript:deleteReturn()" class="easyui-linkbutton" iconCls="icon-remove"
                           plain="true">删除</a>
        </fieldset>
    </div>
</div>
<div region="center" style="margin-top: 5px">
    <table id="dg2" class="easyui-datagrid" fitcolumns="true" rownumbers="true" singleselect="true" fit="true">
        <thead>
        <th field="code" width="30" align="center">商品编码</th>
        <th field="name" width="150" align="center">商品名称</th>
        <th field="model" width="50" align="center">商品型号</th>
        <th field="price" width="50" align="right" formatter="formatPrice">单价</th>
        <th field="num" width="50" align="center">数量</th>
        <th field="unit" width="50" align="center">单位</th>
        <th field="total" width="50" align="right" formatter="formatTotal">总金额</th>
        </thead>
    </table>
</div>
</body>
</body>
</html>